package com.kang.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.kang.dao.GeneralStorageMapper;
import com.kang.pojo.GeneralStorage;
import com.kang.pojo.GgeneralStoragePoJo;
import com.kang.service.GeneralstorageService;
import com.vonechina.entity.page.GeneralStoragePage;

@Service
public class GeneralStorageServiceImpl implements GeneralstorageService {

	@Resource
	private GeneralStorageMapper gsm;

	/**
	 * 根据generalStorageID查询generalstorage数据
	 */
	@Override
	public GeneralStorage selectByGeneralStorage(Integer GeneralStorage) {

		return gsm.selectByGeneralStorage(GeneralStorage);
	}

	/**
	 * 保存普通入库信息
	 */
	@Override
	public int insertone(GeneralStorage gs) {

		return gsm.insertSelective(gs);
	}

	/**
	 * 根据warehousenumber查询generalstorage
	 */
	@Override
	public GeneralStorage selectoneid(String warehousenumber) {

		return gsm.selectoneid(warehousenumber);
	}

	/**
	 * 查询普通入库数据集合
	 */
	@Override
	public List<GgeneralStoragePoJo> selectByWheres(
			GeneralStoragePage generalStoragePage) {
		generalStoragePage.setRows(gsm.selectByWherescount(generalStoragePage));// 查询普通入库总条数
		return gsm.selectByWheres(generalStoragePage);// 查询普通入库数据集合
	}

	/**
	 * 生成普通入库码
	 */
	@Override
	public String selectMaxWarehouseNumber() {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String text = sdf.format(new Date()) + "0001";
		Long no = Long.parseLong(text);
		String max = gsm.selectMaxWarehouseNumber();
		Long l = 0l;
		if (max != null) {
			l = Long.parseLong(max.replaceAll("[a-zA-Z]", ""));
		}
		if (l >= no) {
			no = l + 1;
		}
		return "RK" + no;

	}

	/**
	 * 修改普通入库信息
	 */
	@Override
	public int updateByPrimaryKeySelective(GeneralStorage record) {
		return gsm.updateByPrimaryKeySelective(record);
	}

	/**
	 * 根据generalstorageid删除generalstorage
	 * 
	 * @param generalstorageid
	 * @return
	 */
	@Override
	public int delGeneralStorage(Integer generalstorageid) {
		return gsm.delGeneralStorage(generalstorageid);
	}

}
